<template>
  <div class="nome_namv_box">
    <div class="home_nav">
      <img class="logo" src="@/assets/imgs/logo.png" alt="" />
      <van-dropdown-menu>
        <van-dropdown-item title="" ref="menuRef">
          <div center class="men-list">
            <div
              class="item"
              v-for="(item, index) in navList"
              :key="index"
              @click="handNavTo(item.link)"
            >
              <span class="title">{{ item.name }}</span>
              <img class="icon" src="@/assets/imgs/jiantou.png" alt />
            </div>
          </div>
        </van-dropdown-item>
      </van-dropdown-menu>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, reactive, ref, toRef, toRefs } from "vue";
import { useRouter, onBeforeRouteUpdate } from "vue-router";
import menus from "@/utils/menus";
export default defineComponent({
  name: "NavBar",
  props: {},
  setup() {
    const state = reactive({
      navList: menus(),
      show: false,
      isGoBack: false,
    });
    const routes = useRouter();
    //获取ref dom元素 需要吧这个menuref 返回
    const menuRef = ref(null) as any;
    const handNavTo = (link: string) => {
      routes.push({
        path: link,
      });
      menuRef.value.toggle();
    };
    return { ...toRefs(state), handNavTo, menuRef };
  },
});
</script>
<style lang="scss" >
.nome_namv_box {
  position: sticky;
  top: 0;
  z-index: 99;
  border-bottom: 1px solid #f7f7f7;
  .van-dropdown-menu__title::after {
    display: none;
  }
  .van-popup--top {
    top: 15px;
  }
  .van-overlay {
    top: 16px;
  }
  .van-dropdown-menu__bar {
    box-shadow: 0 0 rgba(100, 101, 102, 0.12);
    background: url(../assets/imgs/menu.png) no-repeat;
    background-size: 100%;
    box-sizing: border-box;
    width: 13px;
    height: 15px;
  }
  .men-list {
    width: 100%;
    background-color: #fff;
    .item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 0;
      border-bottom: 1px solid #ccc;
      .title {
        color: #333;
        font-size: 13px;
        margin-left: 30px;
        box-sizing: border-box;
      }
      .icon {
        margin-right: 30px;
        box-sizing: border-box;
        width: 13px;
        height: 15px;
      }
    }
  }
  .home_nav {
    height: 46px;
    padding: 0 20px;
    box-sizing: border-box;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .logo {
      width: 272px;
      height: 30px;
    }
    .menu {
      height: 16px;
      width: 19px;
    }
    .van-nav-bar__content {
      background-color: #fff;
    }
  }
}
</style>
